package com.jk.controller;

import com.jk.service.EnterpriseService;
import com.jk.vo.CouponInfo;
import com.jk.vo.ProductInfo;
import com.jk.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 企业用户模块控制层
 */
@RestController
@RequestMapping("enterprise")
public class EnterpriseController {
    @Autowired
    private EnterpriseService enterpriseService;

    /**
     * 新增优惠券信息
     * @param couponInfo
     * @return
     */
    @PostMapping("insertCouponInfo")
    public Map insertCouponInfo(CouponInfo couponInfo){
        couponInfo.setCouponId(UUID.randomUUID().toString().replace("-",""));
        couponInfo.setCouponStatus(1);
        couponInfo.setCouponCreateTime(new Date());
        couponInfo.setUserId("aaaa");
        String flag = enterpriseService.insertCouponInfo(couponInfo);
        Map msgMap = new HashMap();
        msgMap.put("flag",flag);
        return msgMap;
    }

    /**
     * 新增产品信息
     */

    @PostMapping("insertProductInfo")
    public Map insertProductInfo(ProductInfo productInfo){
        productInfo.setProductId(UUID.randomUUID().toString().replace("-",""));
        productInfo.setUserId("123456");
        productInfo.setProductStatus(1);
        String flag = enterpriseService.insertProductInfo(productInfo);
        Map msgMap = new HashMap();
        msgMap.put("flag",flag);
        return msgMap;
    }

    /**
     * 分页查询产品信息
     * @param rows
     * @param page
     * @return
     */
    @GetMapping("selectProductInfo")
    public Map selectProductInfo(int rows, int page){

        return enterpriseService.selectProductInfo(rows,page);
    }

    /**
     * 查询企业用户信息
     * @return
     */
    @GetMapping("selectEnterpriseInfo")
    public UserInfo selectEnterpriseInfo(){
        String userId = "89757";
          UserInfo userInfo = enterpriseService.selectEnterpriseInfo(userId);
        return userInfo;
    }
}
